/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DataServices;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author DOANTUNGANH
 */
public class Validate {
    
    public String change(String root){
        root = root.replaceAll("'", "''");
        return root;
    }

    public boolean isWebValid(String web) {
        boolean isValid = false;
        String expression = "^([a-z0-9_-]+\\.)*[a-z0-9_-]+(\\.[a-z]{2,6}){1,2}$";
        CharSequence inputStr = web;
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }

    public boolean isEmailValid(String email) {
        boolean isValid = false;
        String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
        CharSequence inputStr = email;
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }

    public boolean isEmpty(String s) {
        if (s.trim().length() != 0) {
            return false;
        } else {
            return true;
        }
    }

    public boolean isNumber(String number) {
        boolean isValid = false;
        number = number.trim();
        String expression = "[0-9]*\\.?[0-9]+$";
        CharSequence inputStr = number;
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }

    public boolean isPhoneNumber(String number) {
        boolean isValid = false;
        number = number.trim();
        String expression = "[0-9]{6,12}";
        CharSequence inputStr = number;
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }

    public boolean containsBlank(String s) {
        if (s.contains(" ")||s.contains("\t")) {
            return true; // contains blank
        } else {
            return false;
        }
    }
}
